package csu.web.mypetstore.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import csu.web.mypetstore.domain.Cart;
import csu.web.mypetstore.domain.CartItem;
import lombok.Data;

/**
 *
 * @TableName orders
 */
@TableName(value ="orders")
@Data
public class Orders implements Serializable {
    @TableId(type = IdType.AUTO)
    private Integer orderid;
    private String userid;
    private Date orderdate;
    private String shipaddr1;
    private String shipaddr2;
    private String shipcity;
    private String shipstate;
    private Integer shipzip;
    private String shipcountry;
    private String billaddr1;
    private String billaddr2;
    private String billcity;
    private String billstate;
    private Integer billzip;
    private String billcountry;
    @TableField(exist = false)
    private String courier="needed";
    private Double totalprice;
    private String billtofirstname;
    private String billtolastname;
    private String shiptofirstname;
    private String shiptolastname;
    private String creditcard;
    private String exprdate;
    private String cardtype;
    private String locale;
    @TableField(exist = false)
    private String status;
    @TableField(exist = false)
    private List<LineItem> lineItems = new ArrayList<LineItem>();
   @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public void initOrder(Account account, Cart cart) {

        userid =account.getUsername();
        orderdate = new Date();

        shiptofirstname = account.getFirstname();
        shiptolastname = account.getLastname();
        shipaddr1 = account.getAddr1();
        shipaddr2 = account.getAddr2();
        shipcity = account.getCity();
        shipstate = account.getState();
        shipzip = account.getZip();
        shipcountry = account.getCountry();

        billtofirstname = account.getFirstname();
        billtolastname = account.getLastname();
        billaddr1 = account.getAddr1();
        billaddr2 = account.getAddr2();
        billcity = account.getCity();
        billstate = account.getState();
        billzip = account.getZip();
        billcountry = account.getCountry();

        totalprice =cart.getSubTotal().doubleValue();

        creditcard = "999 9999 9999 9999";

        exprdate = "12/03";
        cardtype = "Visa";
        courier = "UPS";
        locale = "CA";
        status = "P";

        Iterator<CartItem> i = cart.getAllCartItems();
        while (i.hasNext()) {
            CartItem cartItem = (CartItem) i.next();
            addLineItem(cartItem);
        }

    }

    public void addLineItem(CartItem cartItem) {
        LineItem lineItem = new LineItem(lineItems.size() + 1, cartItem);
        addLineItem(lineItem);
    }


    public void addLineItem(LineItem lineItem) {
        lineItems.add(lineItem);
    }

    public String getShiptofirstname() {
        return shiptofirstname;
    }

    public void setShiptofirstname(String shiptofirstname) {
        this.shiptofirstname = shiptofirstname;
    }

    public String getShiptolastname() {
        return shiptolastname;
    }

    public void setShiptolastname(String shiptolastname) {
        this.shiptolastname = shiptolastname;
    }

    public String getCreditcard() {
        return creditcard;
    }

    public void setCreditcard(String creditcard) {
        this.creditcard = creditcard;
    }

    public String getExprdate() {
        return exprdate;
    }

    public void setExprdate(String exprdate) {
        this.exprdate = exprdate;
    }

    public String getCardtype() {
        return cardtype;
    }

    public void setCardtype(String cardtype) {
        this.cardtype = cardtype;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }

    public Integer getOrderid() {
        return orderid;
    }

    public void setOrderid(Integer orderid) {
        this.orderid = orderid;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public Date getOrderdate() {
        return orderdate;
    }

    public void setOrderdate(Date orderdate) {
        this.orderdate = orderdate;
    }

    public String getShipaddr1() {
        return shipaddr1;
    }

    public void setShipaddr1(String shipaddr1) {
        this.shipaddr1 = shipaddr1;
    }

    public String getShipaddr2() {
        return shipaddr2;
    }

    public void setShipaddr2(String shipaddr2) {
        this.shipaddr2 = shipaddr2;
    }

    public String getShipcity() {
        return shipcity;
    }

    public void setShipcity(String shipcity) {
        this.shipcity = shipcity;
    }

    public String getShipstate() {
        return shipstate;
    }

    public void setShipstate(String shipstate) {
        this.shipstate = shipstate;
    }

    public Integer getShipzip() {
        return shipzip;
    }

    public void setShipzip(Integer shipzip) {
        this.shipzip = shipzip;
    }

    public String getShipcountry() {
        return shipcountry;
    }

    public void setShipcountry(String shipcountry) {
        this.shipcountry = shipcountry;
    }

    public String getBilladdr1() {
        return billaddr1;
    }

    public void setBilladdr1(String billaddr1) {
        this.billaddr1 = billaddr1;
    }

    public String getBilladdr2() {
        return billaddr2;
    }

    public void setBilladdr2(String billaddr2) {
        this.billaddr2 = billaddr2;
    }

    public String getBillcity() {
        return billcity;
    }

    public void setBillcity(String billcity) {
        this.billcity = billcity;
    }

    public String getBillstate() {
        return billstate;
    }

    public void setBillstate(String billstate) {
        this.billstate = billstate;
    }

    public Integer getBillzip() {
        return billzip;
    }

    public void setBillzip(Integer billzip) {
        this.billzip = billzip;
    }

    public String getBillcountry() {
        return billcountry;
    }

    public void setBillcountry(String billcountry) {
        this.billcountry = billcountry;
    }

    public String getCourier() {
        return courier;
    }

    public void setCourier(String courier) {
        this.courier = courier;
    }

    public Double getTotalprice() {
        return totalprice;
    }

    public void setTotalprice(Double totalprice) {
        this.totalprice = totalprice;
    }

    public String getBilltofirstname() {
        return billtofirstname;
    }

    public void setBilltofirstname(String billtofirstname) {
        this.billtofirstname = billtofirstname;
    }

    public String getBilltolastname() {
        return billtolastname;
    }

    public void setBilltolastname(String billtolastname) {
        this.billtolastname = billtolastname;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", orderid=").append(orderid);
        sb.append(", userid=").append(userid);
        sb.append(", orderdate=").append(orderdate);
        sb.append(", shipaddr1=").append(shipaddr1);
        sb.append(", shipaddr2=").append(shipaddr2);
        sb.append(", shipcity=").append(shipcity);
        sb.append(", shipstate=").append(shipstate);
        sb.append(", shipzip=").append(shipzip);
        sb.append(", shipcountry=").append(shipcountry);
        sb.append(", billaddr1=").append(billaddr1);
        sb.append(", billaddr2=").append(billaddr2);
        sb.append(", billcity=").append(billcity);
        sb.append(", billstate=").append(billstate);
        sb.append(", billzip=").append(billzip);
        sb.append(", billcountry=").append(billcountry);
        sb.append(", totalprice=").append(totalprice);
        sb.append(", billtofirstname=").append(billtofirstname);
        sb.append(", billtolastname=").append(billtolastname);
        sb.append(", shiptofirstname=").append(shiptofirstname);
        sb.append(", shiptolastname=").append(shiptolastname);
        sb.append(", creditcard=").append(creditcard);
        sb.append(", exprdate=").append(exprdate);
        sb.append(", cardtype=").append(cardtype);
        sb.append(", locale=").append(locale);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
